<template>
    <div class="score-container">
        <search-bar @search="handleSearch"></search-bar>
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getList">
            <score-list :list="list"></score-list>
        </van-list>
    </div>
</template>
<script>
import SearchBar from "@/components/SearchBar";
import ScoreList from "./components/ScoreList";
export default {
    name: "score",
    components: {
        SearchBar,
        ScoreList,
    },

    data() {
        return {
            loading: false,
            finished: false,
            pageNo: 0,
            list: [],
            examName: "",
        };
    },

    methods: {
        getList() {
            if (this.$route.query.train) {
                this.$APIs
                    .getTrainScore({
                        pageNo: this.pageNo + 1,
                        pageSize: 10,
                        examName: this.examName,
                    })
                    .then(data => {
                        if (data.data.length) {
                            this.pageNo += 1;
                            this.list.push(...data.data);
                            this.loading = false;
                        } else {
                            this.finished = true;
                            this.loading = false;
                        }
                    });
            } else {
                this.$APIs
                    .getScore({ pageNo: this.pageNo + 1, pageSize: 10, examName: this.examName })
                    .then(data => {
                        if (data.data.length) {
                            this.pageNo += 1;
                            this.list.push(...data.data);
                            this.loading = false;
                        } else {
                            this.finished = true;
                            this.loading = false;
                        }
                    });
            }
        },
        handleSearch(data) {
            this.list = [];
            this.pageNo = 0;
            this.examName = data;
            this.getList();
        },
    },
};
</script>

<style lang="scss" scoped>
.score-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}
</style>
